//
//  HomeViewController.swift
//  Spookiness
//
//  Created by 腾億 on 2017/12/5.
//  Copyright © 2017年 tml. All rights reserved.
//

import UIKit
class HomeViewController: BaseViewController {

    var pageContentView: SGPageContentView!
    var titleView:SGPageTitleView!
    var configure:SGPageTitleViewConfigure!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        setUpNavigationTitleView()
        //右导航栏
        self.navigationItem.rightBarButtonItem = UIBarButtonItem(image: #imageLiteral(resourceName: "nav_search").withRenderingMode(.alwaysOriginal), style: .plain, target: self, action: #selector(rightAction))
        // Do any additional setup after loading the view.
    }

    fileprivate func setUpNavigationTitleView() {
        configure = SGPageTitleViewConfigure.init()
        configure.titleColor = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0).withAlphaComponent(0.5)
        configure.titleSelectedColor = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
        configure.titleFont = UIFont.systemFont(ofSize: 17)
        let titleArr = ["推荐","VIP","订阅","排行"]
        titleView = SGPageTitleView(frame: CGRect(x:-10 , y:0 , width:self.view.width - 80 , height:kSCREEN_NAVBAR ), delegate: self, titleNames: titleArr, configure: configure)
        titleView.isShowIndicator = false//指示器关闭
        titleView.isOpenTitleTextZoom = true//开启文字缩放效果
        titleView.isTitleGradientEffect = false//关闭文字有渐变效果
        titleView.backgroundColor = UIColor.clear
        navigationItem.titleView = titleView
        let recommendVC = RecommendViewController()
        let SubscribeVC = SubscribeViewController()
        let vipVC = VIPViewController()
        let rankVC = RankViewController()
        let childArr:[Any] = [recommendVC, vipVC, SubscribeVC, rankVC]
        let contentViewHeight =  self.view.height - (titleView?.y)!
        pageContentView = SGPageContentView(frame: CGRect(x:0 , y:(titleView?.y)! , width:self.view.width , height:contentViewHeight ), parentVC: self, childVCs: childArr)
        pageContentView.delegatePageContentView = self
        self.view.addSubview(pageContentView)
        
    }

    @objc fileprivate func rightAction() {
        
    }
    
}

extension HomeViewController: SGPageContentViewDelegate {
    func pageContentView(_ pageContentView: SGPageContentView!, progress: CGFloat, originalIndex: Int, targetIndex: Int) {
        self.titleView.setPageTitleViewWithProgress(progress, originalIndex: originalIndex, targetIndex: targetIndex)
    }
}

extension HomeViewController : SGPageTitleViewDelegate {
    func pageTitleView(_ pageTitleView: SGPageTitleView!, selectedIndex: Int) {
        
        self.pageContentView.setPageCententViewCurrentIndex(selectedIndex)
    }
    
    
}
